926A - 2-3-numbers - CodeForces Solution


implementation math *1300

Please click on ads to support us..

Python Code:

l, r = map(int, input().split())
result = set()
for x in range(31):
    for y in range(20):
        v = 2**x*3**y
        if l <= v <= r:
            result.add(v)
print(len(result))

C++ Code:

#include <bits/stdc++.h>

using namespace std;

// /*
//                                                //////////**DEFINES - START**//////////

#define ret return
#define fi first
#define se second
#define mp make_pair
#define all(x) x.begin(), x.end()
#define be(x) x.begin()
#define en(x) x.end()
#define sz(x) x.size()
#define for0(i,n) for (long long  i = 0; i < (n); ++i)
#define for1(i,n) for (long long i = 1; i < (n); ++i)
#define rfor(i,n) for (long long i = (n) - 1; i >= 0; --i)
#define rfor1(i,n) for (long long i = (n) - 1; i >= 1; --i)
#define rep(i,a,n) for (long long i = a; i < ll(n); ++i)
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
#define fastIO() {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define con continue
#define pb push_back
#define pob pop_back
#define watch(x) cout << (#x) << " is " << (x) << endl
#define ins insert
#define len(s) (s).length()
#define gi greater<int>()
#define gll greater<long long>()
#define gstr greater<string>()
#define gpll greater<pair<long long, long long>>()
#define rast(x1,y1,x2,y2) sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
#define rev reverse
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define rs resize
#define last(a) a.back()
#define co count
#define ba(a) a.back()
#define um unordered_map
//#define sqrt sqrt1
#ifdef _DEBUG
bool local = true;
#else
bool local = false;
#endif

//                                                \\\\\\\\\\**DEFINES - END**\\\\\\\\\\
// */

// /*
//                                                //////////**CONSTANTS - START**//////////

const long double pi = 3.141592653589793238462643383279;
const long long mod1 = 1e9 + 7;
const long long mod2 = 998244353;
const long long MAXLL = 9223372036854775807;
const long long MAXINT = 2147483647;

//                                                \\\\\\\\\\**CONSTANTS - END**\\\\\\\\\\
// */

// /*
//                                                //////////**TYPEDEFS - START**//////////

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef pair<double, double> pdd;
typedef long double ld;
typedef double D;
typedef vector<ld> vld;
typedef vector<pair<ld, ld>> vpld;
typedef string str;
typedef set<ll> sll;
typedef set<int> si;
typedef set<str> ss;
typedef set<pii> spii;
typedef multiset<int> msi;
typedef multiset<ll> msll;
typedef multiset<str> mss;
typedef multiset<pii> mspii;
typedef multiset<pll> mspll;
typedef map<str, str> mps;
typedef map<int, int> mpi;
typedef map<ll, ll> mpll;
typedef map<int, vi> mpvi;
typedef map<int, vll> mpvll;
typedef map<char, int> mpci;
typedef multimap<ll, ll> mmpll;
typedef multimap<str, str> mmps;
typedef multimap<int, int> mmpi;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvll;
typedef vector<vector<long double>> vvld;
typedef vector<vector<char>> vvc;
typedef vector<vs> vvs;
typedef vector<D> vD;
typedef set<pair<ll, ll>> spll;
typedef vector<bool> vb;
typedef set<char> sc;
typedef queue<int> qi;
typedef queue<ll> qll;
typedef queue<bool> qb;
typedef queue<pair<ll, ll>> qpll;
typedef vector < vector<pair<int, int>>> vvpii;
typedef vector < vector<pair<ll, ll>>> vvpll;

//                                                \\\\\\\\\\**TYPEDEFS - END**\\\\\\\\\\
// */

// /*
//                                                //////////**TEMPLATES - START**//////////


template <typename T>
istream& operator >> (istream& in, vector <T>& a)
{
	for (T& i : a) in >> i;
	return in;
}
template <typename T1, typename T2>
istream& operator >> (istream& in, vector <pair<T1, T2>>& a)
{
	for (pair<T1, T2>& i : a) in >> i.fi >> i.se;
	return in;
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& a)
{
	for (auto i : a)
	{
		out << i << " ";
	}
	return out;
}
template <typename T1, typename T2>
ostream& operator << (ostream& out, vector <pair<T1, T2>>& a)
{
	for (pair<T1, T2> i : a) out << i.fi << " " << i.se << endl;
	return out;
}
template <typename T1>
ostream& operator << (ostream& out, vector <vector<T1>>& a)
{
	for (vector<T1> i : a)
	{
		for (T1 j : i) out << j << " ";
		out << endl;
	}
	return out;
}
template <typename T1, typename T2>
inline T1 min(T1 a, T2 b)
{
	b = (T1)b;
	ret a > b ? b : a;
}
template <typename T1, typename T2>
inline T1 max(T1 a, T2 b)
{
	b = (T1)b;
	ret a > b ? a : b;
}
template <typename T1, typename T2>
inline void amin(T1& a, T2 b)
{
	a = min(a, b);
}
template <typename T1, typename T2>
inline void amax(T1& a, T2 b)
{
	a = max(a, b);
}


//                                                \\\\\\\\\\**TEMPLATES - END**\\\\\\\\\\
// */




// This bear is a good alternative to duck!!!
/*
	▒▒▒▒      ▒▒▒▒▒▒
  ▒▒░░░░▒▒▒▒▒▒▒░░░░▒▒
 ▒▒░░░░░░▒▒▒▒▒░░░  ░▒▒
▒▒░   ░░▒▒▒▒▒▒▒░░  ░▒▒
▒▒░  ░▒▒▒▒▒▒▒▒▒▒▒ ░▒
 ▒░░▒▒▒▒▒▒█▒▒▒▒▒█▒▒
   ▒▒▒▒▒▒░██▒▒▒▒██ ▒
   ▒▒▒▒▒░░░░███░░░▒▒
   ▒▒▒▒▒░░   ███    ▒▒
	▒▒░░  ▀▄▄▄▄▄▄▀░▒
	 ▒▒▒░     ▀▀ ░▒▒
   ▒▒▒░▒░░░▒▒▒░ ▒▒▒▒▒
  ▒▒▒░▒▒▒▒▒░░░▒░▒▒▒▒▒▒
 ▒▒▒░▒▒▒▒   ▒▒  ▒▒▒▒▒▒▒
 ▒▒▒░▒░░         ░▒▒▒▒
 */

long long rnd(long long l, long long r)
{
	long long a = rand() % (r - l + 1) + l; ret a;
}
double getTime()
{
	ret clock() / (double)CLOCKS_PER_SEC;
};
void solve();
int main()
{
	setlocale(LC_ALL, "rus");
	srand(time(0));
	fastIO();
	if (local)
	{
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
	ll t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	if (local)
	{
		cout.precision(32);
		cout << endl << fixed << "time = " << getTime();
	}
}



/*
	___        __              __   ______          __        _____ __             __          __  __
   /   | _____/ /___  ______ _/ /  / ____/___  ____/ /__     / ___// /_____ ______/ /______   / / / /__  ________
  / /| |/ ___/ __/ / / / __ `/ /  / /   / __ \/ __  / _ \    \__ \/ __/ __ `/ ___/ __/ ___/  / /_/ / _ \/ ___/ _ \
 / ___ / /__/ /_/ /_/ / /_/ / /  / /___/ /_/ / /_/ /  __/   ___/ / /_/ /_/ / /  / /_(__  )  / __  /  __/ /  /  __/
/_/  |_\___/\__/\__,_/\__,_/_/   \____/\____/\__,_/\___/   /____/\__/\__,_/_/   \__/____/  /_/ /_/\___/_/   \___/
*/



void solve()
{
	ll l, r;
	cin >> l >> r;
	ll a = 1;
	ll ans = 0;
	while (a <= r)
	{
		ll b = 1;
		while (a * b <= r)
		{
			if (a * b >= l)
			{
				ans++;
			}
			b *= 3;
		}
		a *= 2;
	}
	cout << ans;
}


Comments

Submit
0 Comments
More Questions

206. Reverse Linked List
83. Remove Duplicates from Sorted List
116. Populating Next Right Pointers in Each Node
145. Binary Tree Postorder Traversal
94. Binary Tree Inorder Traversal
101. Symmetric Tree
77. Combinations
46. Permutations
226. Invert Binary Tree
112. Path Sum
1556A - A Variety of Operations
136. Single Number
169. Majority Element
119. Pascal's Triangle II
409. Longest Palindrome
1574A - Regular Bracket Sequences
1574B - Combinatorics Homework
1567A - Domino Disaster
1593A - Elections
1607A - Linear Keyboard
EQUALCOIN Equal Coins
XOREQN Xor Equation
MAKEPAL Weird Palindrome Making
HILLSEQ Hill Sequence
MAXBRIDGE Maximise the bridges
WLDRPL Wildcard Replacement
1221. Split a String in Balanced Strings
1002. Find Common Characters
1602A - Two Subsequences
1555A - PizzaForces